package com.fan.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fan.dao.OrderDao;
import com.fan.entity.TOrder;
import com.fan.service.OrderListService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.entity.Order;
import com.sixth.until.CommonResult;
import com.sixth.until.TableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;



import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: 老范
 * @create: 2022-04-16 13:33
 **/
@Service
public class OrderListServiceImpl implements OrderListService {
    @Autowired
    private OrderDao orderDao;
    @Override
    public TableResult findOrderList(Integer currentPage, Integer pageSize, Order order) {

        PageHelper.startPage(currentPage,pageSize);
        String mobile = order.getMobile();
        String courseTitle = order.getCourseTitle();
        Date gmtCreate = order.getGmtCreate();
        Date gmtModified = order.getGmtModified();
        String orderNo = order.getOrderNo();
        String teacherName = order.getTeacherName();
        String payType = order.getPayType();
        String status = order.getStatus();
        System.out.println(mobile);

        String startTime= null;
        String editTime= null;
        if (gmtCreate!=null){
            try {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                startTime = null;
                editTime = null;
                String create = gmtCreate +"";
                String modified = gmtModified +"";

                Date format1 = new Date(create);
                Date format2 = new Date(modified);
                String start = format.format(format1);
                String edit = format.format(format2);
                startTime = format.parse(start).toLocaleString();
                editTime = format.parse(edit).toLocaleString();
            } catch (ParseException e) {
                e.printStackTrace();
            }

            List<TOrder> orders = orderDao.selectOrder(mobile, courseTitle, orderNo, teacherName, status, payType,startTime,editTime);

            PageInfo<TOrder> orderPageInfo = new PageInfo<>(orders);
            return new TableResult(2000,"查询成功",orderPageInfo.getTotal(),orderPageInfo.getList());
        }



        List<TOrder> orders = orderDao.selectOrder(mobile, courseTitle, orderNo, teacherName, status, payType,startTime,editTime);

        PageInfo<TOrder> orderPageInfo = new PageInfo<>(orders);
        return new TableResult(2000,"查询成功",orderPageInfo.getTotal(),orderPageInfo.getList());

//        Page<Order> page = new Page<>();
//        QueryWrapper<Order> wrapper = new QueryWrapper<>();
//        if(StringUtils.isNotEmpty(order.getOrderNo())){
//            wrapper.like("order_no",order.getOrderNo());
//        }
//        if(StringUtils.isNotEmpty(order.getCourseTitle())){
//            wrapper.like("course_title",order.getCourseTitle());
//        }
//        if(StringUtils.isNotEmpty(order.getTeacherName())){
//            wrapper.like("teacher_name",order.getTeacherName());
//        }
////        if(StringUtils.isNotEmpty(order.getNickname())){
////            wrapper.like("nickname",order.getNickname());
////        }
//        if(StringUtils.isNotEmpty(order.getMobile())){
//            wrapper.like("mobile",order.getMobile());
//        }
//        if(StringUtils.isNotEmpty(order.getPayType())){
//            wrapper.like("pay_type",order.getPayType());
//        }
////        if(StringUtils.isNotEmpty(order.getTotalFee())){
////            wrapper.like("total_fee",order.getTotalFee());
////        }
//        if(StringUtils.isNotEmpty(order.getStatus())){
//            wrapper.like("status",order.getStatus());
//        }
//        if(StringUtils.isNotEmpty(order.getGmtCreate())){
//            wrapper.like("gmt_create",order.getGmtCreate());
//        }
//        if(StringUtils.isNotEmpty(order.getGmtModified())){
//            wrapper.like("gmt_modified",order.getGmtModified());
//        }
//        QueryWrapper<Order> date = wrapper.select();
//        Page<Order> apricityPage = orderDao.selectPage(page,date);

    }
}
